package de.hwrberlin.remo.algorithm.steps;

import de.hwrberlin.expertsystem.util.ModelEditingHelper;
import de.hwrberlin.remo.model.ElementState;
import de.hwrberlin.remo.model.Fact;

/**
 * Algorithm step, which asks the user for the state
 * of an element.
 * 
 * @author Mario Sänger (IT 09)
 * @version 1.0
 *
 */
public class AskFactStateStep implements AlgorithmStep {

	private Fact fact;
	private ElementState answeredState;
	private ModelEditingHelper editingHelper;
	
	public AskFactStateStep(Fact fact, ElementState answeredState, 
			ModelEditingHelper editingHelper) {
		
		this.fact = fact;
		this.answeredState = answeredState;
		this.editingHelper = editingHelper;
	}
	
	@Override
	public String getLabel() {
		return "User set state of fact '" + fact.getName() 
				+ "' to " + answeredState.getLiteral();
	}

	@Override
	public void perform() {
		this.editingHelper.setElementState(fact, answeredState);
	}

	@Override
	public void revert() {
		this.editingHelper.setElementState(fact, ElementState.UNKNOWN);
	}

	@Override
	public String getExplanation() {
		return "The state of the fact " + fact.getName() + 
				" is unknown, therefore the user was asked.";
	}
}